<template>
  <div class="section-wrap" style="height:100%;margin-top: 40px;">
    <!-- 头部 -->
    <div class="headerBox">
      <div class="header">
        <x-icon type="ios-arrow-left" size="" class="icon-white" @click="goBack"></x-icon>
        需要执行的检查
      </div>
    </div>
    <!-- <vue-better-scroll
      class="wrapper"
      ref="scrollqq"
      :scrollbar="scrollbarObj"
      :pullDownRefresh="pullDownRefreshObj"
      :pullUpLoad="pullUpLoadObj"
      :startY='parseInt(startY)'
      @pullingUp="onPullingUp"
    > -->
      <div class="form-section" style="margin-top: 40px;">
        <div class="info_div2">
          <div class="form-item">
            <div><span>需要执行的检查次数：{{totalCount}}次</span></div>
          </div>
        </div>
        <div class="project_div">
          <ul class="project_list">
            <li v-for='(item,index) in accpentlist' :key="index" @click="$router.push({path:'./needSafeDetails',query:{planId:item.id}})">
              <h4>
                {{item.projectName}}
              </h4>
              <p>
                <input type="text" disabled v-model="item.checkType" style="background-color:#FFF;font-size:14px;">
                <span>{{item.checkDate.substring(0,10)}}</span>
              </p>
              <x-icon type="ios-arrow-right" size="22" class="icon-right"></x-icon>
            </li>
          </ul>
        </div>
      </div>
    <!-- </vue-better-scroll> -->
  </div>

</template>
<script>
  import formatDate from "../../utils/formatDate";
  import VueBetterScroll from "vue2-better-scroll"
  import {
    XHeader,
    Tabbar,
    TabbarItem,
    Group,
    Cell,
    TransferDom,
    Popup
  } from "vux";

  export default {
    directives: {
      TransferDom
    },
    data() {
      return {
        /*下拉刷新*/
        resultlist: [],
        scrollbarObj: {fade: true},
        pullDownRefreshObj: false,
        pullUpLoadObj: {
          threshold: 0,
          txt: {
            more: "加载更多",
            noMore: "没有更多数据了"
          }
        },
        startY: 0,
        scrollToX: 0,
        scrollToY: 0,
        scrollToTime: 700,
        isDisabled: true, // 是否禁止输入
        totalCount: 0, //量化考试
        accpentlist: [
        ],
        classValue: false,
        data: [],
        params: {
          isGetAll:0,
          skipCount: 0,
          maxResultCount: 1000
        },
        selectDepartType: 0
      };
    },
    components: {
      Popup,
      VueBetterScroll
    },
    created() {
      // this.search();
      this.getData();
    },
    mounted(){
      let that = this;
      this.$bridge.registerHandler("setToken", function(data) {
        that.$store.state.Authorization =
          "Bearer " + data;
        //这里data ioS返回的是token值(字符串)
        //that.search();
      });

      this.connectWebViewJavascriptBridge(function(bridge) {
        bridge.init(function(message, responseCallback) {});

        bridge.registerHandler("setToken", function(data) {
          that.$store.state.Authorization =
            "Bearer " + data;
          //that.search();
          //这里data android返回的是token值(字符串)

        });
      });
    },
    methods: {
      connectWebViewJavascriptBridge(callback) {
        if (window.WebViewJavascriptBridge) {
          callback(WebViewJavascriptBridge);
        } else {
          document.addEventListener(
            "WebViewJavascriptBridgeReady",
            function() {
              callback(WebViewJavascriptBridge);
            },
            false
          );
        }
      },
      search() {
        this.params.skipCount = 0;
        this.$axiosAjax.getNeedCheckList(this.params).then(res => {
          this.totalCount = res.data.result.totalCount;
          this.accpentlist = res.data.result.items;
        });
      },
      getData() {
        this.$vux.loading.show({
          text: '加载中...'
        });
        this.$axiosAjax.getNeedCheckList(this.params).then(res => {

          if (res.data.success == true) {
             this.totalCount = res.data.result.totalCount;
             /* this.accpentlist = res.data.result.items;*/

             let relist = res.data.result.items;
            //  第一次加载时，清空页面数据存储数组
             if (this.params.skipCount == 0) {
               this.accpentlist = [];
             }
             this.accpentlist = this.accpentlist.concat(relist);
             let totalAllCount = res.data.result.totalCount;
             let resultCount = this.accpentlist.length;

          // if (parseInt(resultCount) < parseInt(totalAllCount)) {
          //   this.$refs['scrollqq'].forceUpdate(true);
          // } else {
          //   this.$refs['scrollqq'].forceUpdate(false);
          // }
          this.$vux.loading.hide();
          }
        });
      },
      goBack() {
        this.$bridge.callHandler({
          type: 'closePage',
          data: {}
        });
      },
      onPullingUp() {
        let limitcount = this.accpentlist.length;
        this.params.skipCount = limitcount;
        this.getData();
      },
      onPullingDown() {
        this.search();
      },
      nodeClick(item) {
        this.params.beDepartName = item.departName
        this.params.checkDepartId = item.id
        this.classValue = false
      },
    }
  };
</script>
<style lang="less" scoped>
  .info_div2 {
    border-top: none;
    .form-item{
      span{
        font-weight: bold;
      }
    }
  }
  .search-btn {
    width: 200px;
    line-height: 36px;
    border-radius: 20px;
    margin: 23px auto;
    color: #fff;
    background: #469b7a;
    text-align: center;
    font-size:16px;
    letter-spacing: 4px;
  }
  .project_div {
    .project_list {
      padding-left: 20px;
      li {
        border-bottom: 1px solid #efeff4;
        height: 77px;
        position: relative;
        padding-top: 18px;
        padding-right: 22px;
        h4 {
          width: calc(100% - 40px);
          text-overflow: ellipsis;
          white-space: nowrap;
          overflow: hidden;
          font-size: 16px;
          margin-bottom: 8px;
          font-weight: bold;
        }
        p {
          span {
            font-size: 14px;
            color: #666;
          }
          span:first-child {
            margin-right: 40px;
          }
        }
        .project_status {
          margin-top: 14px;
          strong {
            font-size: 12px;
          }
          strong.project_status1 {
            color: #ff7333;
          }
          strong.project_status2 {
            color: #469b7a;
          }
        }
        .vux-x-icon {
          fill: #999;
          right: 20px;
          top: 50%;
          margin-top: -11px;
          position: absolute;
        }
      }
    }
  }
</style>
